/*
 *    Copyright 2011-2012 The Hook Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.hook.showcase.persistence.mongo;

import java.net.UnknownHostException;
import java.util.List;
import java.util.Set;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

/**
 * @author suwuqiang 2011-8-24
 */
public class MongoDemo01 {

	public static void main(String[] args) {
		try {
			Mongo mongo = new Mongo("127.0.0.1", 27017);
			List<String> dbs = mongo.getDatabaseNames();
			for (String dbName : dbs) {
				System.out.println("Current DB is:" + dbName);
				DB db = mongo.getDB(dbName);
				Set<String> colls = db.getCollectionNames();
				for (String collectionName : colls) {
					DBCollection collection = db.getCollection(collectionName);
					long count = collection.count();
					System.out.println("Count of collection:" + collectionName
							+ " user is:" + count);
				}
			}
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (MongoException e) {
			e.printStackTrace();
		}
	}
}
